<?php
namespace Admin\Model;
use Think\Model;
class ConferenceModel extends Model {
    protected $_validate = array(
        array('name','require','会议名不能为空！'),
        array('address','require','会议地点不能为空！'),
        array('banner1','require','请上传海报图片！',0,'unique',4),
        array('logo1','require','请上传Logo图片！',0,'unique',4),
        array('state','require','会议状态不能为空！'),
        array('is_site','require','是否现场报名不能为空！'),
        array('start_time','require','开始时间不能为空！'),
        array('end_time','require','结束时间不能为空！'),
    );

    protected $_map = array(

    );

    protected $_auto = array(
        array('aid','getAid',3,'callback'),
        array('start_time','strtotime',3,'function') ,
        array('end_time','strtotime',3,'function') ,
        array('banner','setBanner',3,'callback'),
        array('logo','setLogo',3,'callback'),
    );


    protected function setBanner(){
        if(!empty($_FILES['banner1']['name'])){//上传不为空，则调用上传
            if(empty($this->info)){//判断Info是否已经有值（是否已经仁德过上传）
                $ret = upload();
                if(!is_array($ret)){
                    retJson("404",$ret);
                }else{
                    $this->info = $ret;
                }
            }
            foreach ($this->info as $k => $v){
                if($v['key'] == "banner1"){
                    return "/Uploads/".$v['savepath'].$v['savename'];
                }
            }
        }
        return I('post.banner1');//返回已经上传的图
    }
    protected function setLogo(){
        if(!empty($_FILES['logo1']['name'])) {//上传不为空，则调用上传
            if(empty($this->info)){//判断Info是否已经有值（是否已经仁德过上传）
                $ret = upload();
                if(!is_array($ret)){
                    retJson("404",$ret);
                }else{
                    $this->info = $ret;
                }
            }
            foreach ($this->info as $k => $v){
                if($v['key'] == "logo1"){
                    return "/Uploads/".$v['savepath'].$v['savename'];
                }
            }
        }
        return I('post.logo');//返回已经上传的图
    }
    protected function getAid(){
        return session('admin.id');
    }

}